package net.topcrazy.blog.service.impl;

import java.util.Map;

import net.topcrazy.base.common.LoginResult;
import net.topcrazy.base.common.SessionGlobal;
import net.topcrazy.base.common.constant.Constant;
import net.topcrazy.blog.dao.TsysAccountDAO;
import net.topcrazy.blog.service.TsysAccountService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 业务对象：TsysAccountServiceImpl，此对象应实现对应业务接口TsysAccountService的所有方法。
 * 创建日期：2012年09月23日11时01分
 * 
 * @author BoyoiFramework
 */
@Service
public class TsysAccountServiceImpl implements TsysAccountService
{
	@Autowired
	private TsysAccountDAO dao;

	@Override
	public LoginResult login(String userName, String password, SessionGlobal sessionGlobal) throws Exception
	{
		LoginResult loginResult= new LoginResult();
		loginResult.setState(false);
		Map<String,Object> result =dao.findAccountByLoginName(userName);
		if(result!=null&&!result.isEmpty()){
			String _password= dao.getTT().getStringFromMap(result, "password");
			String _auditState= dao.getTT().getStringFromMap(result, "auditState");
			if(!password.equals(_password)){
				loginResult.setMsg("密码错误");
				return loginResult;
			}else if(Constant.AccountStatusCode.disable.equals(_auditState)){
				loginResult.setMsg("帐号已被停用");
				return loginResult;
			}else{
				loginResult.setState(true);
				sessionGlobal.setAccountId(dao.getTT().getStringFromMap(result, "accountId"));
				sessionGlobal.setAccountTypeId(dao.getTT().getStringFromMap(result, "accountTypeId"));
				sessionGlobal.setAccountTypeName(dao.getTT().getStringFromMap(result, "accountTypeName"));
				sessionGlobal.setDepartmentCode(dao.getTT().getStringFromMap(result, "departmentCode"));
				sessionGlobal.setDepartmentId(dao.getTT().getStringFromMap(result, "departmentId"));
				sessionGlobal.setDepartmentName(dao.getTT().getStringFromMap(result, "departmentName"));
				sessionGlobal.setDepartmentTypeId(dao.getTT().getStringFromMap(result, "departmentTypeId"));
//				loginResult.setMsg("登录成功");
				return loginResult;
			}
		}else{
			loginResult.setMsg("帐号不存在");
		}
		return loginResult;
	}





	

}
